﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Utility.File
{
    public class TextFile
    {
        #region 成员变量
        private string _FileName;
        #endregion

        #region 构造函数
        public TextFile()
        {
            this._FileName = "";
        }

        public TextFile(string fileName)
        {
            this._FileName = fileName;
        }
        #endregion

        #region 属性
        #region FileName
        public string FileName
        {
            get
            {
                return this._FileName;
            }

            set
            {
                this._FileName = value;
            }
        }
        #endregion
        #endregion

        #region 公共方法
        #region Exist
        public bool Exist()
        {
            try
            {
                return System.IO.File.Exists(this._FileName);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        #endregion

        #region Create
        public void Create()
        {
            try
            {
                System.IO.File.Create(this._FileName);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        #endregion

        #region AppendText
        public void AppendAllText(string textToAppend)
        {
            try
            {
                System.IO.File.AppendAllText(this._FileName, textToAppend);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        #endregion

        #region WriteAllText
        public void WriteAllText(string textToWrite)
        {
            try
            {
                System.IO.File.WriteAllText(this._FileName, textToWrite);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        #endregion

        #region ReadAllText
        public string ReadAllText()
        {
            try
            {
                return System.IO.File.ReadAllText(this._FileName);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        #endregion

        #region CopyTo
        public void CopyTo(string destFileName, bool overwrite)
        {
            System.IO.File.Copy(this._FileName, destFileName, overwrite);
        }

        /// <summary>
        /// 适用于所有类型的文件
        /// </summary>
        /// <param name="destFolder">目标文件夹路径</param>
        public void CopyTo(string destFolder)
        {
            System.IO.File.Copy(this._FileName, destFolder + "\\" + this._FileName, true);
        }
        #endregion

        #region MoveTo
        /// <summary>
        /// 适用于所有类型的文件
        /// </summary>
        /// <param name="destFolder">目标文件夹路径</param>
        public void MoveTo(string destFolder)
        {
            try
            {
                System.IO.File.Move(this._FileName, destFolder + "\\" + this._FileName);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        #endregion

        #region Delete
        /// <summary>
        /// 适用于所有类型的文件
        /// </summary>
        public void Delete()
        {
            try
            {
                System.IO.File.Delete(this._FileName);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        #endregion
        #endregion
    }
}